#include "runner_impl.hpp"

// This file should be compiled without \clr

double RunnerImpl::Run(size_t size, 
	CancelCallback cancellationPending,
	ProgressCallback setCurrentvalue)
{
	unsigned long inside = 0, samples = 0;
	double pi = 0;
	MersenneTwister engine;
	for(;;)
	{
		for (size_t i = 0; i < size; ++i, ++samples)
		{
			double x = engine.Next();
			double y = engine.Next();
			if (x * x + y * y <= 1)
				++inside;     
		}
		pi = 4.0 * (double)inside / samples;
		setCurrentvalue(pi, samples);
		if (cancellationPending())
			break;
	}
	return pi;

}

